package com.example.RemindMe;


import android.app.Activity;
import android.app.AlertDialog;
import android.net.Uri;
import android.os.Bundle;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class RemindMe extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    }

    public void onClickFH (View v)
    {
        int id = v.getId ();
        switch (id) {
            case R.id.fh_button_main:
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.addCategory(Intent.CATEGORY_BROWSABLE);
                intent.setData(Uri.parse("https://www.fh-joanneum.at/"));
                startActivity(intent);
                finish();
                break;
            default:
                break;
        }
    }

    /**
     * Handle the click of a Feature button.
     *
     * @param v View
     * @return void
     */

    public void onClickFeature (View v)
    {
        int id = v.getId ();
        switch (id) {
            case R.id.home_btn_feature1 :
                startActivity (new Intent(getApplicationContext(), AlarmTab.class));
                break;
                
            case R.id.home_btn_feature2 :
                startActivity (new Intent(getApplicationContext(), SettingsActivity.class));
                break;
                
            case R.id.home_btn_feature3 :
                startActivity (new Intent(getApplicationContext(), FindMyCarActivity.class));
                break;
                
            case R.id.home_btn_feature4 :
                if(DialogActivity.noteActvityStarted==false)
                {
                startActivity (new Intent(getApplicationContext(), DialogActivity.class));
                }else{
                    startActivity (new Intent(getApplicationContext(), NoteActivity.class));
                }
                break;

            default:
                break;
        }
    }
  
    //Exit Application when Back Button pressed
    @Override
    public void onBackPressed() {
        backButtonHandler();
        return;
    }
    
    public void backButtonHandler() {
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
        // Setting Dialog Title
        alertDialog.setTitle("Leave application?");
        // Setting Dialog Message
        alertDialog.setMessage("Are you sure you want to leave the application?");
        // Setting Positive "Yes" Button
        alertDialog.setPositiveButton("YES",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    	  System.exit(0);
                    }
                });
        // Setting Negative "NO" Button
        alertDialog.setNegativeButton("NO",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        // Write your code here to invoke NO event
                        dialog.cancel();
                    }
                });
        // Showing Alert Message*if o
        alertDialog.show();
    }
    
    
  //When app is sent to background(when home button clicked) finish the note-activity, retype password
    @Override
	protected void onUserLeaveHint() {
		super.onUserLeaveHint();
		DialogActivity.noteActvityStarted=false;
	}

    

    //----------------------------------Action Bar Methods--------------------------------------------------------------

  
	

	public void onClickHome (View v)
    {
        goHome (this);
    }

    /**
     * Handle the click on the search button.
     *
     * @param v View
     * @return void
     */

    public void onClickSearch (View v)
    {
        startActivity (new Intent(getApplicationContext(), SearchActivity.class));

        //geändert
       // finish();

    }

    /**
     * Handle the click on the About button.
     *
     * @param v View
     * @return void
     */

    public void onClickAbout (View v)
    {
        startActivity (new Intent(getApplicationContext(), AboutActivity.class));


        //geändert
      //  finish();

    }


/**
 */
// More Methods

    /**
     * Go back to the home activity.
     *
     * @param context Context
     * @return void
     */

    public void goHome(Context context)
    {
        final Intent intent = new Intent(context, HomeActivity.class);
        intent.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity (intent);

       //geändert
        //finish();
    }

    /**
     * Use the activity label to set the text in the activity's title text view.
     * The argument gives the name of the view.
     *
     * <p> This method is needed because we have a custom title bar rather than the default Android title bar.
     * See the theme definitons in styles.xml.
     *
     * @param textViewId int
     * @return void
     */

    public void setTitleFromActivityLabel (int textViewId)
    {
        TextView tv = (TextView) findViewById (textViewId);
        if (tv != null) tv.setText (getTitle ());
    } // end setTitleText

    /**
     * Show a string on the screen via Toast.
     *
     * @param msg String
     * @return void
     */

    public void toast (String msg)
    {
        Toast.makeText (getApplicationContext(), msg, Toast.LENGTH_SHORT).show ();
    } // end toast

    /**
     * Send a message to the debug log and display it using Toast.
     */
    public void trace (String msg)
    {
        Log.d("Demo", msg);
        toast (msg);
    }


}
